package org.example.springbootpra1.demos.web;

import org.example.springbootpra1.demos.bean.LoginUser;
import org.example.springbootpra1.demos.util.JwtUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("/api/user")
@Controller
public class LoginController {

    @GetMapping("/login")
    @ResponseBody
    String login(LoginUser user) {
        return JwtUtils.createToken(user);
    }


    @GetMapping("/secure/current_registrant")
    @ResponseBody
    public String currentRegistrant(HttpServletRequest request) {
        Integer id = (Integer) request.getAttribute("id");
        String username = request.getAttribute("userName").toString();
        String password = request.getAttribute("password").toString();
        return "当前用户信息: id="+id+" ,username="+username+" ,password="+password;
    }

}
